package hyl.base.flow.chart;

import hyl.core.MyFun;
import hyl.core.data.CcMap;
import hyl.core.data.IMap;

public abstract class ANode extends AAttribute implements INode {
	


	// 挂载事件, 添加元素时触发
	protected IMount _mountevent = null;

	public ANode() {
		setId();
	}

	
	public ANode(String id) {
		setId(id);

		_props =new CcMap<String, Object>();
	}


	public ANode(String id, INode 父节点) {
		setId(id);
		_props =new CcMap<String, Object>();
		connParent(父节点);
	}

	
	public ANode(String id, INode 父节点, IMount 添加事件) {
		setId(id);
		_props =new CcMap<String, Object>();
		_mountevent = 添加事件;
		connParent(父节点);

	}


	public ANode(String id, INode 父节点, IMap<String, Object> 属性) {
		setId(id);
		_props =属性;
		connParent(父节点);

	}

	protected void callMountEvent(INode 父节点) {
		if (_mountevent != null)
			try {
				_mountevent.run(this, 父节点);
			} catch (Exception e) {
				e.printStackTrace();
			}
	}


	@Override
	public void setId() {
		setId(MyFun.getUUID());
	}

	@Override
	public void setId(String id) {

		if (id == null)
			setId();
		else
			this.id = id;
	}

	@Override
	public boolean connParent(INode 前置节点) {
		return false;
	}

	@Override
	public boolean connChild(INode 后续节点) {
		return false;
	}

	/**
	 * 添加用户时触发遍历事件,主要用来绑定父子节点时需要额外处理的程序
	 * 
	 * 
	 * @param listen
	 */
	public void onAdd(IMount 添加事件) {
		_mountevent = 添加事件;
	}

	public String toString() {
		StringBuilder strB = new StringBuilder();
		strB.append("id:").append(this.id).append('\n');
		return strB.toString();
	}

	IWorker _工人;

	@Override
	public void set工人(IWorker worker) {
		_工人 = worker;
	}

	@Override
	public IWorker get工人() {
		return _工人;
	}

	@Override
	public void del工人() {
		_工人 = null;

	}

}
